﻿using Microsoft.Practices.Unity;
using UnityDemo.InstanceManagerCode.LifeTimeModels;
using UnityDemo.Models;

namespace UnityDemo.InstanceManagerCode.LifetimeTypes
{
    internal class TransientLifetimeManagerDemo : ISample
    {
        //When you register an existing object using the RegisterInstance method, the default behavior is
        //for the container to take over management of the lifetime of the object you pass to this method using
        //the ContainerControlledLifetimeManager. This means that the existing object remains in scope as long as
        //the container is in scope, and it is disposed when the container goes out of scope and is garbage-collected or
        //when code explicitly disposes the container. You can also use this lifetime manager with the RegisterType method
        //to specify that Unity should manage the object as a singleton instance.
        public TransientLifetimeManagerDemo()
        {
            var container = new UnityContainer();
            container.RegisterType<PerInstance>();

            var perInstance1 = container.Resolve<PerInstance>();
            perInstance1.PrintHashCode();

            var perInstance2 = container.Resolve<PerInstance>();
            perInstance2.PrintHashCode();
        }
    }
}